/**
 * Copyright (C) 2017-2018 pinganfang, Inc. All Rights Reserved.
 */
package com.pingan.haofang.searchcloud.solr.schema;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import com.pingan.haofang.searchcloud.api.matedata.FieldMeta;
import com.pingan.haofang.searchcloud.api.matedata.IndexMeta;
import com.pingan.haofang.searchcloud.api.matedata.IndexMetadataHolder;
import com.pingan.haofang.searchcloud.api.matedata.constant.MetadataFieldType;

/**
 * @author huhailiang937
 * @date 2017年5月15日下午11:30:41
 * @since 1.0.0
 */
public class IndexMetadataRegister implements IndexMetadataHolder {

    public Optional<FieldMeta> findFiledMeta(String indexName, String fieldName) {
        IndexMeta indexMeta = this.findIndexMeta(indexName);
        return Optional.of(indexMeta.getFiledMetas().get(fieldName));
    }

    public Optional<String> findPKFieldName(String indexName) {
        return Optional.of("id");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.pingan.haofang.searchcloud.api.matedata.IndexMetadataHolder#
     * findIndexMeta(java.lang.String)
     */
    public IndexMeta findIndexMeta(String indexName) {
        IndexMeta index = new IndexMeta();
        index.setEngineType(0);
        index.setIndexName(indexName);
        index.setHost("127.0.0.1:1221");
        Map<String, FieldMeta> map = new HashMap<String, FieldMeta>();
        map.put("id", new FieldMeta().name("id").pk().type(MetadataFieldType.LONG));
        map.put("name", new FieldMeta().name("name").type(MetadataFieldType.STRING));
        map.put("um", new FieldMeta().name("um").type(MetadataFieldType.STRING));
        map.put("age", new FieldMeta().name("age").type(MetadataFieldType.INT));
        map.put("status", new FieldMeta().name("status").type(MetadataFieldType.INT));
        map.put("ctiy_id", new FieldMeta().name("ctiy_id").type(MetadataFieldType.INT));
        map.put("area_id", new FieldMeta().name("area_id").type(MetadataFieldType.INT));
        map.put("addTime", new FieldMeta().name("addTime").type(MetadataFieldType.INT));
        map.put("l_coordinate", new FieldMeta().name("l_coordinate").type(MetadataFieldType.GEO));
        index.setFiledMetas(map);
        return index;

    }

    /* (non-Javadoc)
     * @see com.pingan.haofang.searchcloud.api.matedata.IndexMetadataHolder#setIndexMeta(java.lang.String, com.pingan.haofang.searchcloud.api.matedata.IndexMeta)
     */
    @Override
    public boolean register(IndexMeta indexMeta) {
        return true;
    }

}
